package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/11.
 */
@HttpInlet(Conn.ACTIVITY_ORDER_VIEW)
public class AppointmentDetailGet extends BaseAsyGet<AppointmentDetailGet.AppointmentDetailEntity> {

    public String id;

    public AppointmentDetailGet(AsyCallBack<AppointmentDetailEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected AppointmentDetailEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            JSONObject mainObject = object.optJSONObject("data");

            AppointmentDetailEntity appointmentDetailEntity = new AppointmentDetailEntity();

            appointmentDetailEntity.id = mainObject.optString("id");
            appointmentDetailEntity.title = mainObject.optString("title");
            appointmentDetailEntity.datetimes = mainObject.optString("datetimes");
            appointmentDetailEntity.amount = mainObject.optString("amount");
            appointmentDetailEntity.time_tip = mainObject.optString("time_tip");
            appointmentDetailEntity.starttime = mainObject.optString("starttime");
            appointmentDetailEntity.endtime = mainObject.optString("endtime");
            appointmentDetailEntity.name = mainObject.optString("name");
            appointmentDetailEntity.mobile = mainObject.optString("mobile");
            appointmentDetailEntity.ischild = mainObject.optString("ischild");
            appointmentDetailEntity.payway = mainObject.optString("payway");
            appointmentDetailEntity.checkinfo = mainObject.optString("checkinfo");
            appointmentDetailEntity.ordernumber = mainObject.optString("ordernumber");
            appointmentDetailEntity.ticket_number = mainObject.optString("ticket_number");
            appointmentDetailEntity.evaluate_status = mainObject.optString("evaluate_status");

            JSONArray array = mainObject.optJSONArray("object_info");

            for (int i = 0; i < array.length(); i++) {

                JSONObject entityObject = array.optJSONObject(i);

                AppointmentEntity appointmentEntity = new AppointmentEntity();

                appointmentEntity.attr = entityObject.optString("attr");
                appointmentEntity.number = entityObject.optString("number");
                appointmentEntity.price = entityObject.optString("price");
                appointmentEntity.title = entityObject.optString("title");

                if (!entityObject.optString("number").equals("0")) {

                    appointmentDetailEntity.appointmentEntityList.add(appointmentEntity);

                }


            }

            return appointmentDetailEntity;

        }

        return null;
    }

    public static class AppointmentDetailEntity {

        public String id, title, datetimes, amount, time_tip, starttime, endtime, name, mobile, ischild, payway, checkinfo, ordernumber, ticket_number,evaluate_status;

        public List<AppointmentEntity> appointmentEntityList = new ArrayList<>();

    }

    public static class AppointmentEntity {

        public String title, price, attr, number;
    }


    /****
     * {
     "code": 200,
     "data": {
     "id": 1,
     "title": "测试4",  //名称
     "datetimes": "2017-01-10", //日期
     "amount": "360", //总价
     "time_tip": "上午", //时间段
     "starttime": "10:00", //开始时间
     "endtime": "11:30", //结束时间
     "name": "阿坤", //姓名
     "mobile": "15846520240", //电话
     "ischild": 1, // 是否带儿童 1 是 0 否
     "payway": "微信", //支付类型
     "checkinfo": 2, //2 待出票 3 已出票 4 已评价
     "ordernumber": 123123123213123123, //订单号
     "ticket_number": 2342342342, //取票号
     "evaluate_status": 2, //评价状态 1是 2否
     "object_info": [ // 租用工具
     {
     "title": "衣服",
     "price": "20.00",
     "attr": "件",
     "number": "3"
     },
     {
     "title": "裤子",
     "price": "20.00",
     "attr": "件",
     "number": "3"
     },
     {
     "title": "滑冰鞋",
     "price": "80.00",
     "attr": "件",
     "number": "3"
     }
     ]
     }
     }
     */


}
